package com.ceres.customer.controller;

import com.ceres.customer.pojo.Menu;
import com.ceres.customer.service.CustMenuService;
import com.ceres.entity.Result;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/custMenu")
public class CustMenuController {

    @Autowired
    private CustMenuService custMenuService;

    /**
     * 分页模糊查询
     *
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage(String keyword, int pageNum, int pageSize) {
        try {
            Page findPage = custMenuService.findPage(keyword, pageNum, pageSize);
            return new Result(true, 2000, findPage);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, 2001);
        }
    }

    /**
     * 查询所有权限
     *
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll() {
        try {
            Map<String, List<Menu>> map = custMenuService.findAll();
            return new Result(true, 2000, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, 2001);
        }
    }
    /**
     * 根据角色查询对应权限
     * @param id
     * @return
     */
    @GetMapping("/findByRoleId")
    public Result findByRoleId(int id) {
        try {
            Map<String, List<Menu>> map = custMenuService.findByRoleId(id);
            return new Result(true, 2000, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, 2001);
        }
    }

}
